﻿using System.ComponentModel;

namespace Microsoft.Extensions.Logging
{
    /// <summary>
    /// 业务自定义日志
    /// </summary>
    public static class LogExtensions
    {
        //NLog.LogLevel.Error, LogType.Web, "全局异常", "全局捕获异常", context.Exception

        /// <summary>
        /// 同时写入到日志到数据库和文件
        /// </summary>
        /// <param name="logLevel">日志等级</param>
        /// <param name="logType">日志类型</param>
        /// <param name="logTitle">标题（255字符）</param>
        /// <param name="message">信息</param>
        /// <param name="exception">异常</param>
        public static void WriteAll(this ILogger logger, LogLevel logLevel, LogType logType, string logTitle, string message, Exception exception = null)
        {
            logger.LogError("{}");
            //先存文件
            // WriteFileLog(logLevel, logType, logTitle, message, exception);
            //后存数据库
            //WriteDbLog(logLevel, logType, logTitle, message, exception);
        }

        /// <summary>
        /// 写日志到数据库
        /// </summary>
        /// <param name="logLevel">日志等级</param>
        /// <param name="logType">日志类型</param>
        /// <param name="logTitle">标题（255字符）</param>
        /// <param name="message">信息</param>
        /// <param name="exception">异常</param>
        public static void WriteDbLog(LogLevel logLevel, LogType logType, string logTitle, string message, Exception exception = null)
        {
            //LogEventInfo theEvent = new LogEventInfo(logLevel, DbLogger.Name, message);
            //theEvent.Properties["LogType"] = logType.ToString();
            //theEvent.Properties["LogTitle"] = logTitle;
            //theEvent.Exception = exception;
            //DbLogger.Log(theEvent);
        }

        ///// <summary>
        ///// 写日志到文件
        ///// </summary>
        ///// <param name="logLevel">日志等级</param>
        ///// <param name="logType">日志类型</param>
        ///// <param name="logTitle">标题（255字符）</param>
        ///// <param name="message">信息</param>
        ///// <param name="exception">异常</param>
        //public static void WriteFileLog(LogLevel logLevel, LogType logType, string logTitle, string message, Exception exception = null)
        //{
        //    LogEventInfo theEvent = new LogEventInfo(logLevel, FileLogger.Name, message);
        //    theEvent.Properties["LogType"] = logType.ToString();
        //    theEvent.Properties["LogTitle"] = logTitle;
        //    theEvent.Exception = exception;

        //    FileLogger.Log(theEvent);
        //}
    }

    public enum LogType
    {
        [Description("网站")]
        Web,

        [Description("数据库")]
        DataBase,

        [Description("Api接口")]
        ApiRequest,

        [Description("中间件")]
        Middleware,

        [Description("其他")]
        Other,

        [Description("Swagger")]
        Swagger,

        [Description("定时任务")]
        Task,
    }
}